package thread;

import java.util.ArrayList;
import java.util.List;

public class LargestNumber {
    public String largestNumber(int[] nums) {
        List<String> newStr = new ArrayList<>();

        for (int num : nums) {
            newStr.add(String.valueOf(num));
        }

        newStr.sort((x, y) -> {
            if (x.charAt(0) != y.charAt(0)) {
                return y.charAt(0) - x.charAt(0);
            }

            String xy = x + y;
            String yx = y + x;

            return yx.compareTo(xy);
        });

        if (newStr.get(0).equals("0")) {
            return "0";
        }

        StringBuilder sb = new StringBuilder();

        for (String a : newStr) {
            sb.append(a);
        }


        return sb.toString();
    }

    public static void main(String[] args) {
        LargestNumber largestNumber = new LargestNumber();
        int[] nums = new int[]{0, 0};
        System.out.println(largestNumber.largestNumber(nums));
    }
}
